草庐IT

java - rabbitMQ 单元测试

全部标签

go - Redigo:在 Apache 负载测试中出现错误

我正在使用库redigo将我的go程序连接到redis。当我运行一个请求时,我得到了正确的结果。但是在负载测试中,使用apache基准测试工具,它在以下情况下起作用:ab-n1000-k-c10-ppost.txt-Tapplication/x-www-form-urlencodedhttp://localhost:8084/abcd但是当请求是:ab-n1000-k-c15-ppost.txt-Tapplication/x-www-form-urlencodedhttp://localhost:8084/abcd我收到错误:panic:dialtcp:6379:toomanyopen

unit-testing - 在 golang 中重置 http 处理程序以进行单元测试

我正在golang中测试一个http服务器,除了一件烦人的事情外,一切看起来都很顺利。在某些时候,当我配置服务器时,在执行http.ListenAndServe之前,我使用http.Handle("/",myrouter)注册了一个处理程序,问题是在下面的测试中,当再次调用配置方法时,我收到以下panic:panic:http:multipleregistrationsfor/[recovered]我想在干净的环境中运行每个测试,但还没有找到拆除http.DefaultServeMux的方法,有没有一种方便的方法可以通过“无效”来做到这一点或者重新配置测试环境,以便每个测试都在新环境中

golang gorilla/mux 和测试,在哪里存储路由

在我看过的大多数文档中,gorillamux都被建议像这样使用...funcmain(){m:=mux.Router()m.HandleFunc("/",FuncNameOrDef)http.ListenAndServe(":8080",m)}这很好,但它给我留下了一个问题,因为据我所知,为了测试,我需要重新声明mux和路由,除非我在像这样的函数之外声明mux和路由。.var(m=mux.Router()_=m.HandleFunc("/",FuncNameOrDef))然后在我的测试中这样做...funcTestSomeView(t*testing.T){ts:=httptest.N

go - 如何使 rabbitmq 消费者超时?

我让rabbitmq消耗队列,但一旦客户端被订阅,它就会永远消耗队列。声明和退出是否有超时,即队列为空后?msgs,err:=ch.Consume(q.Name,//queue"",//consumertrue,//auto-ackfalse,//exclusivefalse,//no-localfalse,//no-waitnil,//args)formsg:=rangemsgs{log.Printf("Receivedmessagewithmessage:%s",msg.Body)} 最佳答案 您可以使用thestandardG

json - Golang Godog REST API 测试失败

在过去的2周里,我一直在研究GODOG,这是一个类似于golang的bdd的cucumber。我发现它非常有趣,最近我花更多时间为我的RESTAPI编写测试。最近,我一直在努力通过我的一项考试。这一个包含一个JSON结构,该结构本身内部有子JSON。此外,我正在按照以下链接找到的确切示例进行测试:https://github.com/DATA-DOG/godog/tree/master/examples/api我有一个像这样的结构:typeStatusstruct{ErrorCodestring`json:"ERROR_CODE"`ErrorTextstring`json:"ERROR

unit-testing - 仅测试文件中的掩码包名称

为了追求100%的单元测试覆盖率,我们尝试在一个函数中测试多行代码。相关函数调用运行时包://functionNamereturnsastringrepresentingthefunctionnameofthefunctionnstackframesabovethecaller.//ifn=0,thenameofthefunctioncallingfunctionName()willbereturned.funcfunctionName(nint)string{pc,_,_,ok:=runtime.Caller(n+1)if!ok{return"unknownfunction"}me:

unit-testing - 在 Go 中进行单元测试时,是否可以动态断言两个值是否相等?

我刚刚开始使用Go。我正在编写单元测试,我希望能够使用表格进行测试,其中要与实际结果进行比较的结果有时应该或不应该相等。例如,这是我目前拥有的代码:packagemainimport("github.com/stretchr/testify/assert""testing")funcTestFunc(t*testing.T){tables:=[]struct{inputstringcomparisonResultstringshouldBeEqualbool}{{"someirrelevantinput","someresult",true,},{"someotherirrelevan

java - gRPC:如何使用 Go 服务器在 Java 客户端中获取多个返回值

我有一个ProtocolBuffer文件:syntax="proto3";packagev1api;optionjava_multiple_files=true;optionjava_package="myApp.v1";optionjava_outer_classname="V1";serviceAPI{rpcLogin(LoginRequest)returns(LoginResponse)}messageLoginRequest{intpin=1}messageLoginResponse{stringtoken=1}我的服务器是用Go(一种可以返回多个值的语言)编写的,我的客户端是

unit-testing - 如何模拟/单元测试嵌套函数

我有一个函数在其他函数中被调用。send_api.gofunction*send_api*(client*http.Client,urlstring)map[string]string,error{//sendapirequestandparsetheresponseandreturnthedictreturndictmapforeg:{applefruit}}然后这个函数在ma​​in()函数中被调用func*main()*{getmap:=send_api(client*http.Client,"test.com")}good.gofunc*get_dict_key*(keystr

testing - 如何在单元测试中处理新服务器功能

对我来说,单元测试有工作量。所以我使用gotests生成样板测试代码案例。server.gofuncNewServer(cfg*Config,lnet.Listener,driverDriver,dbstore.Store)*Server{s:=&Server{cfg:cfg,listener:l,leader:"",driver:driver,db:db,}s.server=&http.Server{Handler:s.createMux(),}returns}gotests生成server_test.go:funcTestNewServer(t*testing.T){fakeCfg